(function(){
    app.service('openstackData',[function () {
        var service = {
            platformId:'',
            type:'host',
            host:{},
            platformData:{}
        };
        return service;
    }]);
    app.controller('openstackTabCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','webSocket','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,webSocket,openstackData) {
            $rootScope.moduleTitle = '平台管理 > OpenStack';//定义当前页
            $rootScope.link = '/statics/css/user.css';
            switch (openstackData.type) {
                case 'host':
                    $scope.active13 = true;
                    break;
                case 'vm':
                    $scope.active1 = true;
                    break;
                case 'network':
                    $scope.active6 = true;
                    break;
                case 'volume':
                    $scope.active3 = true;
                    break;
                case 'snapshot':
                    $scope.active4 = true;
                    break;
                case 'account':
                    $scope.active2 = true;
                    break;
                case 'size':
                    $scope.active5 = true;
                    break;
                case 'route':
                    $scope.active7 = true;
                    break;
            };
            var myScroll;
            //获取云平台列表
            var getList = function (flag) {
                httpLoad.loadData({
                    url: '/cloudVendor/list',
                    method: 'POST',
                    data:{
                        page:1,
                        rows:10000,
                        params:JSON.stringify([{"param": {"type": "OPENSTACK"}, "sign": "EQ"}])
                    } ,
                    noParam: true,
                    success: function (data) {
                        if (data.success) {
                            $scope.platformData = data.data.rows;
                            if (!data.data.total||data.data.total==0) {
                                loadTabData('',1);
                                $scope.pop('请添加平台', 'info');
                                return;
                            }
                            if (openstackData.platformId) {
                                $scope.platformData.forEach(function (item) {
                                    if (item.id == openstackData.platformId) {
                                        $scope.selectCell(item);//有平台id直接通过select获取
                                    }});
                            } else $scope.selectCell($scope.platformData[0]);//无平台id通过点击
                            $('.platform-container>div').width(124 * (data.data.total + 1));
                            myScroll = new IScroll('.platform-container', {
                                scrollX: true,
                                scrollY: true,
                                momentum: false,
                                snap: true
                            });
                        }
                    }
                });
            };
            getList(1);
            $scope.goLeft = function () {
                if(myScroll)  myScroll.goToPage(-10, 0);
            };
            $scope.goRight = function () {
                if(myScroll)  myScroll.goToPage(10, 0);
            };
            $scope.editPlatform = function ($event,id) {
                $event.stopPropagation();
                var modalInstance = $modal.open({
                    templateUrl: '/statics/tpl/config/openstack/platform/addModal.html',
                    controller: 'addOpenstackPlatformModalCtrl',
                    backdrop: 'static',
                    resolve: {
                        id: function () {
                            return id || '';
                        }
                    }
                });
                modalInstance.result.then(function (data) {
                    if(!id) openstackData.platformId = data.data;//添加时默认选中添加的平台
                    getList();
                });
            };
            $scope.delPlatform = function ($event,row) {
                $event.stopPropagation();
                $scope.selectCell(row);
                var modalInstance = $modal.open({
                    templateUrl: '/statics/tpl/template/delModal.html',
                    controller: 'delModalCtrl',
                    backdrop: 'static',
                    resolve:{
                        tip: function () {
                            return '此操作会删除整个平台下的所有资源，不会对原有平台上的资源做操作，确定是否删除？';
                        },
                        btnList:function(){
                            return  [{name:'删除',type:'btn-info'},{name:'取消',type:'btn-cancel'}];
                        }
                    }
                });
                modalInstance.result.then(function() {
                    httpLoad.loadData({
                        url: '/cloudVendor/remove',
                        method: 'POST',
                        data: {id:row.id},
                        success: function (data) {
                            if (data.success) {
                                if (row.id == openstackData.platformId) openstackData.platformId = '';
                                getList();
                                $scope.pop('平台删除成功');
                            }
                        }
                    });
                });
            };
            $scope.selectCell = function (row,flag) {
                if(row.selected) return;
                $scope.platformData.forEach(function (item) {
                    item.selected = false;
                });
                row.selected = true;
                openstackData.platformId = row.id;
                openstackData.platformData = row;
                if (!flag)  $scope.selectTab('',1);//对平台进行操作时不对相应tab数据做更新
            };
            //获取云平台详情，进行数据整合
            var getVendorDetail = function () {
                httpLoad.loadData({
                    url: '/cloudVendor/detail',
                    method: 'GET',
                    data: {id: openstackData.platformId},
                    success: function (data) {
                        if (data.success) {
                            openstackData.platformData.isLoadDetail = false;
                            var obj = ['instance','hostCount','dataStoreCount','imageCount','templateCount'];
                            obj.forEach(function (item) {
                                openstackData.platformData[item] = data.data[item];
                            });
                        }
                    }
                });
            };
            $scope.sync = function ($event,row) {
                $event.stopPropagation();
                $scope.selectCell(row);
                var modalInstance = $modal.open({
                    templateUrl: '/statics/tpl/config/openstack/platform/sync.html',
                    controller: 'mSyncOpenstackModalCtrl',
                    resolve: {
                        id: function () {
                            return row.id;
                        }
                    }
                });
                modalInstance.result.then(function () {
                    $scope.selectTab();
                }, function () {
                });
            };
            //请求列表数据
            var loadTabData = function (page) {
                switch (openstackData.type) {
                    case 'host':
                        openstackData.hostFun(page);
                        break;
                    case 'vm':
                        openstackData.vmFun(page);
                        break;
                    case 'network':
                        openstackData.networkFun(page);
                        break;
                    case 'volume':
                        openstackData.volumeFun(page);
                        break;
                    case 'snapshot':
                        openstackData.snapshotFun(page);
                        break;
                    case 'account':
                        openstackData.accountFun(page);
                        break;
                    case 'size':
                        openstackData.sizeFun(page);
                        break;
                    case 'route':
                        openstackData.routeFun(page);
                        break;
                }
            };
            $scope.selectTab = function (type) {
                //if (!openstackData.platformId) return;
                openstackData.type = type || openstackData.type;
                loadTabData(1);
            };
            var socketObj = {
                host:'openstack.host',
                vm:'openstack.vm',
                network:'openstack.network',
                volume:'openstack.volume',
                snapshot:'openstack.snapshot',
                account:'openstack.image',
                size:'openstack.size',
                route:'openstack.route'
            };
            //websocket异步操作
            webSocket.onmessage({
                message:function (data) {
                    if($rootScope.currentUrl=='app.config.openstackTab'&&(data.operate == socketObj[openstackData.type]||data.operate=='openstack.sync'&& data.data.vendorId == openstackData.platformId)){
                        loadTabData();
                        if(data.operate=='openstack.sync'||openstackData.platformData.isLoadDetail) getVendorDetail();
                    }
                }
            });
        }
    ]);
    //添加/编辑平台ctrl
    app.controller('addOpenstackPlatformModalCtrl', ['$scope', '$modalInstance', '$stateParams', 'httpLoad', 'id',
        function ($scope, $modalInstance, $stateParams, httpLoad, id) {
            $scope.modalName = '添加平台';
            var url = '/cloudVendor/create';
            $scope.updateData = {};
            $scope.typeData = ["V2", "V3"];
            $scope.updateData.CloudVendor = {
                version:'V2',
                type:'OPENSTACK'
            };
            $scope.isEditable = false;
            var getData = function () {
                var list = ["id", "name",  "tenant", "account", "password", "address","domainName","projectName","version","remark"];
                httpLoad.loadData({
                    url: '/cloudVendor/detail',
                    method: 'GET',
                    data: {id: id},
                    success: function (data) {
                        if (data.success) {
                            var data = data.data;
                            for (var i = 0; i < list.length; i++) {
                                var name = list[i];
                                $scope.updateData.CloudVendor[name] = data[name];
                            }
                        }
                    }
                });
            };
            if(id) {
                $scope.isEditable = true;
                $scope.modalName = '编辑平台';
                url = '/cloudVendor/modify';
                getData();
            }
            //保存按钮
            $scope.ok = function () {
                if($scope.updateData.CloudVendor.version=='V2') {
                    delete $scope.updateData.CloudVendor.projectName;
                    delete $scope.updateData.CloudVendor.domainName;
                }else if($scope.updateData.CloudVendor.version=='V3'){
                    delete $scope.updateData.CloudVendor.tenant;
                }
                httpLoad.loadData({
                    url: url,
                    method: 'POST',
                    data: $scope.updateData,
                    success: function (data) {
                        if (data.success) {
                            var text = '平台添加成功';
                            if(id) text = '平台编辑成功';
                            $scope.pop(text);
                            $modalInstance.close(data);
                        }
                    }
                });
            }
            $scope.cancle = function () {
                $modalInstance.dismiss('cancel');
            };
        }
    ]);
    app.controller('openstackHostCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 平台管理';//定义当前页
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取集群列表
            $scope.getData = function(page){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/vhost/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.vmHostList = data.data.rows;
                            $scope.totalCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                                return;
                            } else $scope.isImageData = false;
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.hostFun = $scope.getData;
            $scope.vmHostTable = 1;
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
            $scope.paramd = {};
            $scope.itemsByPage = 10;
            //详情虚机记录
            $scope.getVmData = function (page,name) {
                $scope.paramd.params = JSON.stringify([{"param": {"hostname": name || $scope.supplierDetail.name,"vendorId": openstackData.platformId}, "sign": "EQ"}]);
                httpLoad.loadData({
                    url: '/vhost/listvmbyvhost',
                    method: 'POST',
                    data: $scope.paramd,
                    noParam: true,
                    success: function (data) {
                        if (data.success) {
                            $scope.vmList = data.data;
                            if(!data.data){
                                $scope.isImageDatad = true;
                                return;
                            }
                            $scope.total = data.data.length;
                            if ($scope.total == 0) {
                                $scope.isImageDatad = true;
                                return;
                            } else $scope.isImageDatad = false;
                            angular.forEach($scope.vmList, function (item, index) {
                                //状态
                                switch (item.status) {
                                    case 'RUNNING':
                                        item.statusColor = 'success';
                                        break;
                                    case 'STOPPED':
                                        item.statusColor = 'warning';
                                        break;
                                    case 'STOPPING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'STARTING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'SUSPENDED':
                                        item.statusColor = 'primary';
                                        break;
                                    case 'SUSPENDING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'ACTIVING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'PAUSED':
                                        item.statusColor = 'warning';
                                        break;
                                    case 'PAUSING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'RECOVERING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'BUILDING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'RESTARTING':
                                        item.statusColor = 'default';
                                        break;
                                    case 'EXPIRED':
                                        item.statusColor = 'default';
                                        break;
                                    case 'EXCEPTION':
                                        item.statusColor = 'danger';
                                        break;
                                    case 'SYNSEXCEPTION':
                                        item.statusColor = 'danger';
                                        break;
                                }
                            });
                        } else {
                            $scope.isImageDatad = true;
                        }
                    }
                });
            };
            //跳转详情页
            $scope.detail = function ($event,row) {
                $event.stopPropagation();
                httpLoad.loadData({
                    url:'/vhost/detail',
                    method:'GET',
                    data: {id: row.id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.supplierDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;
                        }
                    }
                });
                $scope.getVmData(1,row.name);
            };
            //性能报表
            $scope.catPerformance = function (name) {
                var obj = {
                    flag:1,
                    name:name,
                    vendorId:openstackData.platformId
                };
                sessionStorage.setItem('performance',JSON.stringify(obj))
                $state.go('app.config.openstackPerformance')
            };
        }
    ]);
    app.controller('openstackaccountCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 镜像管理';
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取镜像列表
            $scope.getData = function(page){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/image/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.imageList = data.data.rows;
                            $scope.totalCount = openstackData.platformData.imageCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                                return;
                            } else $scope.isImageData = false;
                            angular.forEach($scope.imageList, function(data,index){
                                if(data.status=='QUEUED') {
                                    data.status1 = '排队中';
                                    data.statusColor = 'info';
                                }else if(data.status=='ACTIVE') {
                                    data.status1 = '运行中';
                                    data.statusColor = 'success';
                                }else if(data.status=='DELETED') {
                                    data.status1 = '已删除';
                                    data.statusColor = 'danger';
                                }else {
                                    data.status1 = '运行中';
                                    data.statusColor = 'success';
                                }
                            });
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            $scope.imageTable = 2;
            openstackData.accountFun = $scope.getData;
            //编辑
            $scope.update = function($event,$index,row,key,size){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/account/updateAccount.html',
                    controller : 'updateopenstackAccountModalCtrl',
                    resolve : {
                        idData : function(){
                            return row.id;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //删除
            $scope.remove = function(id,$event,$index,key){
                if($event) $event.stopPropagation();
                $scope.removeData= {"id" : id};
                var action = 2;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/removeVolume.html',
                    controller : 'removeopenstackVolumeModalCtrl',
                    resolve : {
                        action : function(){
                            return action;
                        },
                        removeData : function(){
                            return $scope.removeData;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
            $scope.paramd = {
                page:1,
                rows:10
            };
            //跳转详情页
            $scope.detail = function ($event,id) {
                $event.stopPropagation();
                httpLoad.loadData({
                    url:'/image/detail',
                    method:'GET',
                    data: {id: id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.imageDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;
                            if($scope.imageDetail.status=='QUEUED') {
                                $scope.imageDetail.status1 = '排队中';
                                $scope.imageDetail.statusColor = 'info';
                            }else if($scope.imageDetail.status=='ACTIVE') {
                                $scope.imageDetail.status1 = '运行中';
                                $scope.imageDetail.statusColor = 'success';
                            }else if($scope.imageDetail.status=='DELETED') {
                                $scope.imageDetail.status1 = '已删除';
                                $scope.imageDetail.statusColor = 'danger';
                            }else{
                                $scope.imageDetail.status1 = '运行中';
                                $scope.imageDetail.statusColor = 'success';
                            }
                        }
                    }
                });
            };
        }
    ]);
    //编辑ctrl
    angular.module('app').controller('updateopenstackAccountModalCtrl',['$scope','$modalInstance','httpLoad','$stateParams','idData','openstackData',
        function($scope,$modalInstance,httpLoad,$stateParams,idData,openstackData){ //依赖于modalInstance
            $scope.updateData = {};
            //获取详情数据反显
            $scope.getDetail = function(){
                httpLoad.loadData({
                    url:'/image/detail',
                    method:'GET',
                    data: {id: idData},
                    success:function(data){
                        if(data.success){
                            $scope.vmDetail = data.data;
                            var updateItem = ['id','name'];
                            for(var i=0;i<updateItem.length;i++){
                                var item = updateItem[i];
                                $scope.updateData[item] = $scope.vmDetail[item];
                            }
                        }
                    }
                });
            };
            $scope.getDetail();
            $scope.ok = function(){
                httpLoad.loadData({
                    url:'/image/modify',
                    method:'POST',
                    data: $scope.updateData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    app.controller('openstackvolumeCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 块设备管理';
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取块设备管理列表
            $scope.getData = function(page,action){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/volume/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.volumeList = data.data.rows;
                            $scope.totalCount = data.data.total;
                            //如果是删除，手动更新数据存储的数量
                            if(action==0) openstackData.platformData.dataStoreCount = $scope.totalCount;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                                return;
                            } else $scope.isImageData = false;
                            angular.forEach($scope.volumeList, function(data,index){
                                if(data.status=='AVAILABLE') {
                                    data.status1 = '可用配额';
                                    data.statusColor = 'info';
                                }else if(data.status=='IN_USE') {
                                    data.status1 = '正在使用';
                                    data.statusColor = 'success';
                                }else if(data.status=='BUILDING') {
                                    data.status1 = '创建中';
                                    data.statusColor = 'primary';
                                }else if(data.status=='DELETING') {
                                    data.status1 = '删除中';
                                    data.statusColor = 'warning';
                                } else {
                                    data.status1 = '异常';
                                    data.statusColor = 'danger';
                                }
                            });
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.volumeFun = $scope.getData;
            $scope.volumeTable = 1;
            //新增
            $scope.add = function($event){
                if($scope.volumeTable == 1){
                    var modalInstance = $modal.open({
                        templateUrl : '/statics/tpl/config/openstack/volume/addVolume.html',
                        controller : 'addopenstackVolumeModalCtrl'
                    });
                    modalInstance.result.then(function(){
                        $scope.getData();
                        openstackData.platformData.isLoadDetail = true;
                    },function(){});
                }
            };
            //编辑
            $scope.update = function($event,$index,row,key,size){
                $event.stopPropagation();
                if(row.status=='IN_USE') return;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/volume/updateVolume.html',
                    controller : 'updateopenstackVolumeModalCtrl',
                    resolve : {
                        idData : function(){
                            return row.id;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //删除
            $scope.remove = function(row,$event,$index,key){
                if($event) $event.stopPropagation();
                if(row.status=='IN_USE') return;
                $scope.removeData= {"id" : row.id};
                var action = 1;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/removeVolume.html',
                    controller : 'removeopenstackVolumeModalCtrl',
                    resolve : {
                        action : function(){
                            return action;
                        },
                        removeData : function(){
                            return $scope.removeData;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData($scope.param.page,0);
                },function(){});
            };
            $scope.paramd = {
                page:1,
                rows:10
            };
            //详情操作记录
            $scope.getOperateData = function(page,id){
                id = id||$scope.volumeDetail.volumeId;
                $scope.paramd.page = page || $scope.paramd.page;
                var params = {
                        page: $scope.paramd.page,
                        rows: $scope.paramd.rows
                    },
                    searchParam = [];
                searchParam.push({"param":{"volumeId":id},"sign":"EQ"});
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/snapshot/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            $scope.snapshotList = data.data.rows;
                            $scope.totalCountd = data.data.total;
                            if($scope.totalCountd==0){
                                $scope.isImageDatad10 = true;
                                return;
                            }else {
                                $scope.isImageDatad10 = false;
                                angular.forEach($scope.snapshotList, function(data,index){
                                    if(data.status=='AVAILABLE') {
                                        data.status1 = '可用配额';
                                        data.statusColor = 'info';
                                    }else if(data.status=='BUILDING') {
                                        data.status1 = '创建中';
                                        data.statusColor = 'success';
                                        data.isException = true;
                                    }else if(data.status=='DELETING') {
                                        data.status1 = '删除中';
                                        data.statusColor = 'warning';
                                    }else{
                                        data.status1 = '错误';
                                        data.statusColor = 'danger';
                                    }
                                });
                            }
                        }else{
                            $scope.isImageDatad10 = true;
                        }
                    }
                });
            };
            //跳转详情页
            $scope.detail = function (row) {
                httpLoad.loadData({
                    url:'/volume/detail',
                    method:'GET',
                    data: {id: row.id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.volumeDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;

                            if($scope.volumeDetail.status=='AVAILABLE') {
                                $scope.volumeDetail.status1 = '可用配额'; $scope.volumeDetail.statusColor = 'info';
                            }else if($scope.volumeDetail.status=='IN_USE') {
                                $scope.volumeDetail.status1 = '正在使用';$scope.volumeDetail.statusColor = 'success';
                            }else if($scope.volumeDetail.status=='BUILDING') {
                                $scope.volumeDetail.status1 = '创建中';$scope.volumeDetail.statusColor = 'primary';
                            }else if($scope.volumeDetail.status=='DELETING') {
                                $scope.volumeDetail.status1 = '删除中';$scope.volumeDetail.statusColor = 'warning';
                            }else {
                                $scope.volumeDetail.status1 = '异常';$scope.volumeDetail.statusColor = 'danger';
                            }
                            $scope.getOperateData(1,$scope.volumeDetail.volumeId);
                        }
                    }
                });
            };
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
        }
    ]);
    //新增ctrl
    angular.module('app').controller('addopenstackVolumeModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','openstackData',
        function($rootScope,$scope,$modalInstance,httpLoad,openstackData){ //依赖于modalInstance
            $scope.addData = {};
            //获取可用区域数据
            $scope.getRegion = function(){
                httpLoad.loadData({
                    url:'/region/list',
                    method: 'POST',
                    data: {"id":openstackData.platformId},
                    success:function(data){
                        if(data.success){
                            $scope.regionData = data.data;
                            angular.forEach($scope.regionData, function(data,index){
                                //默认选中第一个区域
                                if(index==0){
                                    data.isRegionActive = true;
                                    $scope.addData.region = data.id;
                                }
                                else data.isRegionActive = false;
                            });
                        }
                    }
                });
            };
            $scope.getRegion();
            //选择可用区域
            $scope.chooseRegion = function(item){
                angular.forEach($scope.regionData, function(data,index){
                    data.isRegionActive = false;
                    if(data.id==item.id){
                        data.isRegionActive = !item.isRegionActive;
                    }
                    if(data.isRegionActive){
                        $scope.addData.region = data.id;
                    }
                });
            };
            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                if(!$scope.addData.region){
                    $scope.pop('请选择可用区域','error');
                    return;
                }
                httpLoad.loadData({
                    url:'/volume/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });

            };

            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //编辑ctrl
    angular.module('app').controller('updateopenstackVolumeModalCtrl',['$scope','$modalInstance','httpLoad','$stateParams','idData','openstackData',
        function($scope,$modalInstance,httpLoad,$stateParams,idData,openstackData){ //依赖于modalInstance
            $scope.updateData = {};
            //获取详情数据反显
            $scope.getDetail = function(){
                httpLoad.loadData({
                    url:'/volume/detail',
                    method:'GET',
                    data: {id: idData},
                    success:function(data){
                        if(data.success){
                            $scope.vmDetail = data.data;
                            var updateItem = ['id','name','remark'];
                            for(var i=0;i<updateItem.length;i++){
                                var item = updateItem[i];
                                $scope.updateData[item] = $scope.vmDetail[item];
                            }
                        }
                    }
                });
            };
            $scope.getDetail();
            $scope.ok = function(){
                httpLoad.loadData({
                    url:'/volume/modify',
                    method:'POST',
                    data: $scope.updateData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
     }]);
    app.controller('openstacksnapshotCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 快照管理';
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取快照管理列表
            $scope.getData = function(page){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                if($scope.searchByVolumeName&&$scope.searchByVolumeName!=""){
                    searchParam.push({"param":{"volumeName":$scope.searchByVolumeName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/snapshot/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.snapshotList = data.data.rows;
                            $scope.totalCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                                return;
                            } else $scope.isImageData = false;
                            angular.forEach($scope.snapshotList, function(data,index){
                                data.isException = false;
                                if(data.status=='AVAILABLE') {
                                    data.status1 = '可用配额';
                                    data.statusColor = 'info';
                                }else if(data.status=='BUILDING') {
                                    data.status1 = '创建中';
                                    data.statusColor = 'success';
                                    data.isException = true;
                                }else if(data.status=='DELETING') {
                                    data.status1 = '删除中';
                                    data.statusColor = 'warning';
                                }else{
                                    data.status1 = '错误';
                                    data.statusColor = 'danger';
                                }
                            });
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.snapshotFun = $scope.getData;
            //新增
            $scope.add = function($event){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/snapshot/addSnapshot.html',
                    controller : 'addopenstackSnapshotModalCtrl'
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //删除
            $scope.remove = function(id,$event,$index,key,isException){
                if($event) $event.stopPropagation();
                if(isException) return;
                $scope.removeData= {"id" : id};
                var action = 3;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/removeVolume.html',
                    controller : 'removeopenstackVolumeModalCtrl',
                    resolve : {
                        action : function(){
                            return action;
                        },
                        removeData : function(){
                            return $scope.removeData;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //跳转详情页
            $scope.detail = function (id) {
                httpLoad.loadData({
                    url:'/snapshot/detail',
                    method:'GET',
                    data: {id: id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.snapshotDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;

                            if($scope.snapshotDetail.status=='AVAILABLE') {
                                $scope.snapshotDetail.status1 = '可用配额';
                                $scope.snapshotDetail.statusColor = 'info';
                            }else if($scope.snapshotDetail.status=='BUILDING') {
                                $scope.snapshotDetail.status1 = '创建中';
                                $scope.snapshotDetail.statusColor = 'success';
                            }else if($scope.snapshotDetail.status=='DELETING') {
                                $scope.snapshotDetail.status1 = '删除中';
                                $scope.snapshotDetail.statusColor = 'warning';
                            }else{
                                $scope.snapshotDetail.status1 = '错误';
                                $scope.snapshotDetail.statusColor = 'danger';
                            }
                        }
                    }
                });
            };
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
        }
    ]);
    //新增ctrl
    angular.module('app').controller('addopenstackSnapshotModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','openstackData',
        function($rootScope,$scope,$modalInstance,httpLoad,openstackData){ //依赖于modalInstance
            $scope.addData = {};
            $scope.param = {
                rows: 6
            };
            //获取快设备数据
            $scope.getVolume = function(){
                var params = {
                        simple : true
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId,"status":"AVAILABLE"},"sign":"EQ"}];
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/volume/list',
                    method:'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            $scope.volumeData = data.data.rows;
                        }
                    }
                });
            };
            $scope.getVolume();
            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                httpLoad.loadData({
                    url:'/snapshot/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });

            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    app.controller('openstackVmListCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$window','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$window,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 平台管理';//定义当前页
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取云主机列表
            $scope.getData = function(page,sorter){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                if($scope.searchByStatus&&$scope.searchByStatus!=""){
                    var a = 0;
                    for(var i=0;i<searchParam.length;i++){
                        if(searchParam[i].sign=="LK") {
                            a = 1;
                            searchParam[i].param.status = $scope.searchByStatus;
                        }
                    }
                    if(a==0) searchParam.push({"param":{"status":$scope.searchByStatus},"sign":"LK"});
                }
                if(sorter&&sorter!=""&&JSON.stringify(sorter)!="{}") params.sorter = JSON.stringify(sorter);
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/vm/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.vmList = data.data.rows;
                            $scope.totalCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                                return;
                            } else $scope.isImageData = false;
                            angular.forEach($scope.vmList, function(data,index){
                                //状态
                                data.isShowRecover = data.isRecover = data.isShowPaused = data.isPaused = data.isShowSuspended = data.isSuspended = data.isShowActive = data.isActive = data.isShowStart = data.isStart = data.isShowStop = data.isStop = false;
                                data.isBackup = false;data.isCatPerformance = true;
                                //异常的虚拟机或者是没有instanceId的虚拟机,控制台置为灰色
                                if(data.instanceId) data.isControl = false;
                                else data.isControl = true;
                                data.isOffline = true;
                                switch(data.status){
                                    case 'RUNNING':
                                        data.isShowStop = true;data.isStop = false;
                                        data.isShowRestart = true;data.isRestart = false;
                                        data.isShowStart = false;
                                        data.isShowPaused = true;data.isPaused = false;
                                        data.isShowSuspended = true;data.isSuspended = false;
                                        data.statusColor = 'success';
                                        break;
                                    case 'STOPPED':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = true;data.isStart = false;
                                        data.isShowRecover = true;data.isRecover = false;
                                        data.isShowActive = true;data.isActive = false;
                                        data.statusColor = 'warning';
                                        data.isOffline = false;
                                        data.isException1 = true;
                                        break;
                                    case 'STOPPING':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = true;data.isStart = false;
                                        data.isShowRecover = true;data.isRecover = true;
                                        data.isShowActive = true;data.isActive = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'STARTING':
                                        data.isShowStop = true;data.isStop = true;
                                        data.isShowRestart = true;data.isRestart = false;
                                        data.isShowStart = false;
                                        data.isShowPaused = true;data.isPaused = true;
                                        data.isShowSuspended = true;data.isSuspended = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'SUSPENDED':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = false;
                                        data.isShowActive = true;data.isActive = false;
                                        data.isException = true;data.isBackup = true;data.isException1 = true;
                                        data.isShowRecover = true;data.isRecover = false;
                                        data.statusColor = 'primary';
                                        break;
                                    case 'SUSPENDING':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = false;
                                        data.isShowActive = true;data.isActive = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'ACTIVING':
                                        data.isShowStop = true;data.isStop = true;
                                        data.isShowRestart = true;data.isRestart = false;
                                        data.isShowStart = false;
                                        data.isShowPaused = true;data.isPaused = true;
                                        data.isShowSuspended = true;data.isSuspended = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'PAUSED':
                                        data.isControl = true;
                                        data.isShowStop = false;data.isCatPerformance = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = false;
                                        data.isShowRecover = true;data.isRecover = false;
                                        data.isException1 = true;
                                        data.statusColor = 'warning';
                                        break;
                                    case 'PAUSING':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = false;
                                        data.isShowRecover = true;data.isRecover = true;
                                        data.isException1 = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'RECOVERING':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = false;
                                        data.isShowPaused = true;data.isPaused = true;
                                        data.isShowSuspended = true;data.isSuspended = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'PAUSING':
                                        data.isShowStop = true;data.isStop = true;
                                        data.isShowRestart = true;data.isRestart = false;
                                        data.isShowStart = false;
                                        data.statusColor = 'default';
                                        break;
                                    case 'BUILDING':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = true;data.isStart = true;
                                        data.isShowRecover = true;data.isRecover = true;
                                        data.isShowActive = true;data.isActive = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'RESTARTING':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = false;
                                        data.isShowPaused = true;data.isPaused = true;
                                        data.isShowSuspended = true;data.isSuspended = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'EXPIRED':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = true;data.isStart = true;
                                        data.isShowRecover = true;data.isRecover = true;
                                        data.isShowActive = true;data.isActive = true;
                                        data.statusColor = 'default';
                                        break;
                                    case 'EXCEPTION':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = true;data.isStart = true;
                                        data.isShowRecover = true;data.isRecover = true;
                                        data.isShowActive = true;data.isActive = true;
                                        data.isException = true;data.isBackup = true;data.isException1 = true;data.isControl = true;
                                        data.statusColor = 'danger';
                                        break;
                                    case 'SYNSEXCEPTION':
                                        data.isShowStop = false;
                                        data.isShowRestart = true;data.isRestart = true;
                                        data.isShowStart = true;data.isStart = true;
                                        data.isShowRecover = true;data.isRecover = true;
                                        data.isShowActive = true;data.isActive = true;
                                        data.isException = true;data.isBackup = true;data.isException1 = true;data.isControl = true;
                                        data.statusColor = 'danger';
                                        break;
                                }
                            });
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.vmFun = $scope.getData;
            $scope.vmTable = 1;$scope.isSyncBtn = true;$scope.isAddBtn = true;
            //状态数据
            $scope.statusData = [{"value":"RUNNING","name":"运行中"},{"value":"STOPPED","name":"关机"},{"value":"SUSPENDED","name":"挂起"},{"value":"PAUSED","name":"停止"},{"value":"EXCEPTION","name":"异常"}];
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
            $scope.showPassword = function(value){
                $scope[value] = !$scope[value];
            };
            //排序
            $scope.sortList = {};$scope.sorter = {};
            $scope.sort = function(sortName){
                if($scope.sorter&&JSON.stringify($scope.sorter)!="{}"){
                    for(var a in $scope.sorter){
                        if(a!=sortName) {
                            $scope.sortList[a] = 2;
                            delete $scope.sorter[a];
                        }
                    }
                }
                switch($scope.sortList[sortName]){
                    case 0:
                        $scope.sortList[sortName] = 1;
                        break;
                    case 1:
                        $scope.sortList[sortName] = 2;
                        break;
                    case 2:
                        $scope.sortList[sortName] = 0;
                        break;
                }
                if($scope.sortList[sortName] == 2&&$scope.sorter[sortName]) delete $scope.sorter[sortName];
                else $scope.sorter[sortName] = $scope.sortList[sortName]+"";

                $scope.getData($scope.param.page,$scope.sorter);
            };
            //控制台
            $scope.control = function($event,row){
                $event.stopPropagation();
                var newWindow = $window.open();
                httpLoad.loadData({
                    url:'/vm/vncconsole',
                    method:'POST',
                    data: {"vncType":"novnc","serverId":row.instanceId,"id":row.vendorId,"region":"nova"},
                    success:function(data){
                        if(data.success==true){
                            newWindow.location.href = data.data.url;
                        }else{
                            newWindow.close();
                        }
                    }
                });
            };
            //新增
            $scope.add = function($event){
                $event.stopPropagation();
                $state.go('app.config.openstackAdd',{id:openstackData.platformId});
            };
            //编辑
            $scope.update = function($event,row,isAction){
                $event.stopPropagation();
                if(isAction==true) return;
                $state.go('app.config.openstackUpdate',{vmId:row.id,id:openstackData.platformId});
            };
            //新增快照
            $scope.addSnapshot = function($event,id,isAction){
                $event.stopPropagation();
                if(isAction==true) return;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/vm/addSnapshot2.html',
                    controller : 'addopenstackSnapshotModalCtrl2',
                    resolve : {
                        id : function(){
                            return id;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                    openstackData.platformData.isLoadDetail = true;
                },function(){});
            };
            $scope.catPerformance = function (name) {
                var obj = {
                    flag:2,
                    name:name,
                    vendorId:openstackData.platformId
                };
                sessionStorage.setItem('performance',JSON.stringify(obj))
                $state.go('app.config.openstackPerformance')
            };
            //在线迁移
            $scope.onlineTransfer = function($event,row,isAction){
                $event.stopPropagation();
                if(isAction==true) return;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/vm/onlinetransfer.html',
                    controller : 'onlinetransferOpenstackModalCtrl',
                    resolve : {
                        id : function(){
                            return row.id;
                        },
                        hostName:function(){
                            return row.hostName;
                        },
                        hostId:function(){
                            return row.hostId;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //离线迁移
            $scope.offlineTransfer = function($event,row,isAction){
                $event.stopPropagation();
                if(isAction==true) return;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/vm/offlinetransfer.html',
                    controller : 'offlinetransferOpenstackModalCtrl',
                    resolve : {
                        id : function(){
                            return row.id;
                        },
                        name:function(){
                            return row.name;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //删除6,备份3，快照4，恢复0，暂停7，挂起8，激活9，重启1，开机2，关机5
            $scope.remove = function($event,row,value,isAction){
                if($event) $event.stopPropagation();
                if(isAction==true) return;
                //只有挂起状态和停止状态的虚机有恢复操作(value==0)
                //挂起状态的恢复操作用接口/vm/recovery，停止状态的恢复接口用/vm/unpause(强行改变停止状态的value值)
                if(value==0&&row.status=='PAUSED') value=10;
                var txt = '';
                if(value==6) {
                    if(row.status!='STOPPED'){
                        txt = '虚机正在运行中，无法删除';
                    }
                }
                $scope.removeData= {"id":row.id};
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/vm/remove.html',
                    controller : 'removeOpenstackModalCtrl',
                    resolve : {
                        removeData : function(){
                            return $scope.removeData;
                        },
                        value: function(){
                            return value;
                        },
                        txt:function(){
                            return txt;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                    $timeout(function() {
                        $scope.getData();
                    }, 5000);
                    openstackData.platformData.isLoadDetail = true;
                },function(){});
            };
            $scope.paramd = {
                page:1,
                rows:10
            };
            //详情操作记录
            $scope.getOperateData = function(page,id){
                id = id||$scope.vmDetail.id;
                $scope.paramd.page = page || $scope.paramd.page;
                var params = {
                        page: $scope.paramd.page,
                        rows: $scope.paramd.rows
                    },
                    searchParam = [];
                searchParam.push({"param":{"vmId":id},"sign":"EQ"});
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/res/event/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            if(data.data){
                                $scope.eventList = data.data.rows;
                                $scope.totalCountd = data.data.total;
                                $scope.isImageDatad = false;
                            }
                        }else{
                            $scope.isImageDatad = true;
                        }
                    }
                });
            };
            //跳转详情页
            $scope.detail = function ($event,id) {
                $event.stopPropagation();
                httpLoad.loadData({
                    url:'/vm/detail',
                    method:'GET',
                    data: {id: id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.vmDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;
                            //状态处理
                            switch($scope.vmDetail.status){
                                case 'RUNNING':
                                    $scope.vmDetail.statusColor = "success";
                                    break;
                                case 'STOPPED':
                                    $scope.vmDetail.statusColor = "warning";
                                    break;
                                case 'STOPPING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'STARTING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'SUSPENDED':
                                    $scope.vmDetail.statusColor = "primary";
                                    break;
                                case 'SUSPENDING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'ACTIVING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'PAUSED':
                                    $scope.vmDetail.statusColor = "warning";
                                    break;
                                case 'PAUSING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'RECOVERING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'PAUSING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'BUILDING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'RESTARTING':
                                    $scope.vmDetail.statusColor = "default";
                                    break;
                                case 'EXCEPTION':
                                    $scope.vmDetail.statusColor = "danger";
                                    break;
                                case 'SYNSEXCEPTION':
                                    $scope.vmDetail.statusColor = "danger";
                                    break;
                            }

                            //密码处理
                            var password = '';
                            if($scope.vmDetail.password){
                                for(var i=0;i<$scope.vmDetail.password.length;i++){
                                    password +='*';
                                }
                                $scope.vmDetail.password = password;
                            }
                        }
                    }
                });
                //获取列表数据
                $scope.getOperateData(1,id);
            };
        }
    ]);
    //删除ctrl
    angular.module('app').controller('removeOpenstackModalCtrl',['$scope','$modalInstance','httpLoad','removeData','value','txt',
        function($scope,$modalInstance,httpLoad,removeData,value,txt){
            var url;
            //删除6,备份3，快照4，恢复0，停止7，挂起8，激活9，重启1，开机2，关机5
            //挂起状态的恢复操作用接口/vm/recovery，停止状态的恢复接口用/vm/unpause
            if(value==0){
                $scope.actionName = '恢复';
                url = '/vm/recovery';
            }
            if(value==10){
                $scope.actionName = '恢复';
                url = '/vm/unpause';
            }
            if(value == 1){
                $scope.actionName = '重启';
                url = '/vm/restart';
            }
            if(value == 2){
                $scope.actionName = '开机';
                url = '/vm/start';
            }
            if(value == 3){
                $scope.actionName = '备份';
                url = '/vm/backup';
            }
            if(value == 4){
                $scope.actionName = '快照';
                url = '/vm/snapshoot';
            }
            if(value == 5){
                $scope.actionName = '关机';
                url = '/vm/stop';
            }
            if(value == 6){
                $scope.actionName = '删除';
                url = '/vm/remove';
            }
            if(value == 7){
                $scope.actionName = '停止';
                url = '/vm/pause';
            }
            if(value == 8){
                $scope.actionName = '挂起';
                url = '/vm/suspend';
            }
            if(value == 9){
                $scope.actionName = '激活';
                url = '/vm/active';
            }
            $scope.ok = function(){
                httpLoad.loadData({
                    url:url,
                    method:'POST',
                    data: removeData,
                    success:function(data){
                        if(data.success==true){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }else{
                            if(value==1||value==2||value==5) $scope.pop(data.message,'error');
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //虚机新增快照ctrl
    angular.module('app').controller('addopenstackSnapshotModalCtrl2',['$rootScope','$scope','$modalInstance','httpLoad','$stateParams','id','openstackData',
        function($rootScope,$scope,$modalInstance,httpLoad,$stateParams,id,openstackData){ //依赖于modalInstance
            $scope.addData = {
                id:openstackData.platformId,
                serverId:id
            };
            $scope.ok = function(){
                httpLoad.loadData({
                    url:'/vm/snapshot',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //在线迁移ctrl
    angular.module('app').controller('onlinetransferOpenstackModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','openstackData','id','hostName','hostId',
        function($rootScope,$scope,$modalInstance,httpLoad,openstackData,id,hostName,hostId){
            $scope.syncData = {
                id: openstackData.platformId,
                serverId:id,
                diskOverCommit:false,
                blockMigration:false,
                live:true
            };
            $scope.hostName = hostName;$scope.hostData = [];
            //获取主机数据
            $scope.getHost = function(){
                var params = {
                        page: 1,
                        rows: 9999
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/vhost/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            var dataList = data.data.rows;
                            angular.forEach(dataList, function(data,index){
                                if(data.id != hostId) $scope.hostData.push(data);
                                if(data.name==$scope.hostName) $scope.name = data.name;
                            });
                        }
                    }
                });
            };
            $scope.getHost();
            //判断新主机列表是否为空
            $scope.checkHost = function(){
                if($scope.hostData.length==0) $scope.pop('当前无可用主机','error');
            };
            $scope.ok = function(){
                httpLoad.loadData({
                    url:'/vm/OSMigrate',
                    method:'POST',
                    data: $scope.syncData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            };
        }]);
    //离线迁移ctrl
    angular.module('app').controller('offlinetransferOpenstackModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','openstackData','id','name',
        function($rootScope,$scope,$modalInstance,httpLoad,openstackData,id,name){
            $scope.syncData = {
                id:openstackData.platformId,
                serverId:id,
                live:false
            };
            $scope.name = name;
            $scope.ok = function(){
                httpLoad.loadData({
                    url:'/vm/OSMigrate',
                    method:'POST',
                    data: $scope.syncData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            };
        }]);
    //同步ctrl
    angular.module('app').controller('mSyncOpenstackModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','$stateParams','id',
        function($rootScope,$scope,$modalInstance,httpLoad,$stateParams,id){
            $scope.syncData = {};$scope.modelTitle = '提示';
            $scope.param = {
                rows: 6
            };
            var url = '/cloudVendor/sync';
            $scope.ok = function(){
                $scope.syncData.id = id;
                httpLoad.loadData({
                    url:url,
                    method:'POST',
                    data: $scope.syncData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            };
        }]);
    app.controller('openstacksizeCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 配置管理';
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取配置管理列表
            $scope.getData = function(page){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/flavor/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.sizeList = data.data.rows;
                            $scope.totalCount = openstackData.platformData.templateCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                            } else $scope.isImageData = false;
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.sizeFun = $scope.getData;
            //新增
            $scope.add = function($event){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/size/addsize.html',
                    controller : 'addsizeModalCtrl'
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };

            //删除
            $scope.remove = function(id,$event,$index,key){
                if($event) $event.stopPropagation();
                $scope.removeData= {"id" : id};
                var action = 5;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/removeVolume.html',
                    controller : 'removeopenstackVolumeModalCtrl',
                    resolve : {
                        action : function(){
                            return action;
                        },
                        removeData : function(){
                            return $scope.removeData;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            }
            //跳转详情页
            $scope.detail = function ($event,id) {
                $event.stopPropagation();
                httpLoad.loadData({
                    url:'/flavor/detail',
                    method:'GET',
                    data: {id: id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.volumeDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;
                        }
                    }
                });
            };
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
        }
    ]);
    //新增ctrl
    angular.module('app').controller('addsizeModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','openstackData',
        function($rootScope,$scope,$modalInstance,httpLoad,openstackData){ //依赖于modalInstance
            $scope.addData = {};

            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                httpLoad.loadData({
                    url:'/flavor/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    app.controller('openstacknetworkCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 网络管理';
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取网络管理列表
            $scope.getData = function(page){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/network/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.networkList = data.data.rows;
                            $scope.totalCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                                return;
                            } else $scope.isImageData = false;
                            angular.forEach($scope.networkList, function(data,index){
                                if(data.status=='RUNNING') {
                                    data.status1 = '运行中';
                                    data.statusColor = 'success';
                                } else{
                                    data.status1 = '异常';
                                    data.statusColor = 'danger';
                                }
                                if(data.shared==true) data.shared1 = '是';
                                if(data.shared==false) data.shared1 = '否';
                            });
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.networkFun = $scope.getData;
            $scope.openstackNetworkTable = 1;
            //新增
            $scope.add = function($event,size){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/network/addNetwork.html',
                    controller : 'addopenstackNetworkModalCtrl'
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //编辑
            $scope.update = function($event,$index,row,key,size){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/network/updateNetwork.html',
                    controller : 'updateopenstackNetworkModalCtrl',
                    resolve : {
                        idData : function(){
                            return row.id;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //新增子网
            $scope.add1 = function($event,networkId,size){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/network/addSubnet.html',
                    controller : 'addopenstackSubnetModalCtrl',
                    resolve : {
                        networkId : function(){
                            return networkId;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //新增端口
            $scope.add2 = function($event,networkId,size){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/network/addPort.html',
                    controller : 'addopenstackPortModalCtrl',
                    resolve : {
                        networkId : function(){
                            return networkId;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //删除
            $scope.remove = function(id,action){
                $scope.removeData= {"id" : id};
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/removeVolume.html',
                    controller : 'removeopenstackVolumeModalCtrl',
                    resolve : {
                        action : function(){
                            return action;
                        },
                        removeData : function(){
                            return $scope.removeData;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            $scope.paramd = {
                page:1,
                rows:10
            };
            //详情操作记录
            $scope.getOperateData1 = function(page,id){
                $scope.paramd.page = page || $scope.paramd.page;
                $scope.operationId = id || $scope.operationId;
                var params = {
                        page: $scope.paramd.page,
                        rows: $scope.paramd.rows
                    },
                    searchParam = [];
                searchParam.push({"param":{"networkId":$scope.operationId,"vendorId":openstackData.platformId},"sign":"EQ"});
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/subnet/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            if(data.data){
                                $scope.subnetList = data.data.rows;
                                $scope.totalCountd = data.data.total;
                                $scope.isImageDatad = false;
                                if(data.data.rows.length==0) $scope.isImageDatad = true;
                            }
                        }else $scope.isImageDatad = true;
                    }
                });
            };
            $scope.paramd2 = {
                page:1,
                rows:10
            };
            $scope.getOperateData2 = function(page,id){
                $scope.paramd2.page = page || $scope.paramd2.page;
                $scope.operationId = id || $scope.operationId;
                var params = {
                        page: $scope.paramd2.page,
                        rows: $scope.paramd2.rows
                    },
                    searchParam = [];
                searchParam.push({"param":{"networkId":$scope.operationId,"vendorId":openstackData.platformId},"sign":"EQ"});
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/port/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            if(data.data){
                                $scope.portList = data.data.rows;
                                $scope.totalCountd2 = data.data.total;
                                $scope.isImageDatad2 = false;
                                if(data.data.rows.length==0) $scope.isImageDatad2 = true;
                            }
                        }else $scope.isImageDatad2 = true;
                    }
                });
            };
            //跳转详情页
            $scope.detail = function (row) {
                $scope.openstackNetworkTable = 1;
                httpLoad.loadData({
                    url:'/network/detail',
                    method:'GET',
                    data: {id: row.id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.volumeDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;
                            if($scope.volumeDetail.status=='RUNNING') {
                                $scope.volumeDetail.status1 = '运行中';
                                $scope.volumeDetail.statusColor = 'success';
                            } else {
                                $scope.volumeDetail.status1 = '异常';
                                $scope.volumeDetail.statusColor = 'danger';
                            }

                            if($scope.volumeDetail.shared==true) $scope.volumeDetail.shared1 = '是';
                            if($scope.volumeDetail.shared==false) $scope.volumeDetail.shared1 = '否';
                        }
                    }
                });
                //获取列表数据
                $scope.getOperateData1(1,row.networkId);
                $scope.getOperateData2(1,row.networkId);
            };
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
        }
    ]);
    //新增ctrl
    angular.module('app').controller('addopenstackNetworkModalCtrl',['$scope','$modalInstance','httpLoad','openstackData',
        function($scope,$modalInstance,httpLoad,openstackData){ //依赖于modalInstance
            $scope.addData = {};
            $scope.categoryData = [{"value":"LOCAL","name":"Local"},{"value":"FLAT","name":"Flat"},{"value":"VLAN","name":"VLAN"},{"value":"GRE","name":"GRE（通用路由封装）"},{"value":"VXLAN","name":"VXLAN"}];
            $scope.statusData = [{"value":true,"name":"开启"},{"value":false,"name":"关闭"}];
            $scope.addData.type = "LOCAL";$scope.addData.adminStateup = true;
            $scope.addData.shared = false;$scope.addData.isRouterExternal = false;
            $scope.checkType = function(){
                switch($scope.addData.type){
                    case "LOCAL":
                        $scope.isPhyNetwork = false;$scope.isSementationId = false;
                        break;
                    case "FLAT":
                        $scope.isPhyNetwork = true;$scope.isSementationId = false;
                        $scope.addData.phyNetwork = "default";
                        break;
                    case "VLAN":
                        $scope.isPhyNetwork = true;$scope.isSementationId = true;
                        $scope.addData.phyNetwork = "DVS01";
                        break;
                    case "GRE":
                        $scope.isPhyNetwork = false;$scope.isSementationId = true;
                        break;
                    case "VXLAN":
                        $scope.isPhyNetwork = false;$scope.isSementationId = true;
                        break;
                };   
            };

            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                switch($scope.addData.type){
                    case "LOCAL":
                        if($scope.addData.phyNetwork) delete $scope.addData.phyNetwork;
                        break;
                    case "FLAT":
                        if($scope.addData.segmentationId) delete $scope.addData.segmentationId;
                        break;
                    case "VLAN":
                        break;
                    case "GRE":
                        if($scope.addData.phyNetwork) delete $scope.addData.phyNetwork;
                        break;
                    case "VXLAN":
                        if($scope.addData.phyNetwork) delete $scope.addData.phyNetwork;
                        break;
                };   

                httpLoad.loadData({
                    url:'/network/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //编辑ctrl
    angular.module('app').controller('updateopenstackNetworkModalCtrl',['$scope','$modalInstance','httpLoad','$stateParams','idData','openstackData',
        function($scope,$modalInstance,httpLoad,$stateParams,idData,openstackData){ //依赖于modalInstance
            $scope.updateData = {};
            $scope.statusData = [{"value":true,"name":"开启"},{"value":false,"name":"关闭"}];

            //获取详情数据反显
            $scope.getDetail = function(){
                httpLoad.loadData({
                    url:'/network/detail',
                    method:'GET',
                    data: {id: idData},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.vmDetail = data.data;
                            var updateItem = ['id','name','adminStateup','shared'];
                            for(var i=0;i<updateItem.length;i++){
                                var item = updateItem[i];
                                $scope.updateData[item] = $scope.vmDetail[item];
                            }
                            $scope.updateData.adminStateup = ''+ $scope.updateData.adminStateup;
                        }
                    }
                });
            };
            $scope.getDetail();
            $scope.ok = function(){
                $scope.updateData.id = idData;
                httpLoad.loadData({
                    url:'/network/modify',
                    method:'POST',
                    data: $scope.updateData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //新增子网ctrl
    angular.module('app').controller('addopenstackSubnetModalCtrl',['$scope','$modalInstance','httpLoad','openstackData','networkId',
        function($scope,$modalInstance,httpLoad,openstackData,networkId){ //依赖于modalInstance
            $scope.addData = {};$scope.addData.networkId = networkId;
            //获取可用区域数据
            $scope.getRegion = function(){
                httpLoad.loadData({
                    url:'/region/list',
                    method: 'POST',
                    data: {"id":openstackData.platformId},
                    success:function(data){
                        if(data.success){
                            $scope.regionData = data.data;
                            angular.forEach($scope.regionData, function(data,index){
                                //默认选中第一个区域
                                if(index==0){
                                    data.isRegionActive = true;
                                    $scope.addData.region = data.id;
                                }
                                else data.isRegionActive = false;
                            });
                        }
                    }
                });
            };
            $scope.getRegion();
            //选择可用区域
            $scope.chooseRegion = function(item){
                angular.forEach($scope.regionData, function(data,index){
                    data.isRegionActive = false;
                    if(data.id==item.id){
                        data.isRegionActive = !item.isRegionActive;
                    }
                    if(data.isRegionActive){
                        $scope.addData.region = data.id;
                    }
                });
            };
            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                if(!$scope.addData.region){
                    $scope.pop('请选择可用区域','error');
                    return;
                }
                httpLoad.loadData({
                    url:'/subnet/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //新增端口ctrl
    angular.module('app').controller('addopenstackPortModalCtrl',['$scope','$modalInstance','httpLoad','openstackData','networkId',
        function($scope,$modalInstance,httpLoad,openstackData,networkId){ //依赖于modalInstance
            $scope.addData = {};$scope.addData.networkId = networkId;
            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                httpLoad.loadData({
                    url:'/port/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //删除ctrl
    angular.module('app').controller('removeopenstackVolumeModalCtrl',['$scope','$modalInstance','httpLoad','removeData','action',
        function($scope,$modalInstance,httpLoad,removeData,action){ //依赖于modalInstance
            var url;
            switch(action){
                case 1:
                    url = '/volume/remove';operationTxt = '';$scope.txt = '是否删除云硬盘？';
                    break;
                case 2:
                    url = '/image/remove';operationTxt = '';$scope.txt = '是否删除镜像？';
                    break;
                case 3:
                    url = '/snapshot/remove';operationTxt = '';$scope.txt = '是否删除快照？';
                    break;
                case 4:
                    url = '/network/remove';operationTxt = '网络删除成功';$scope.txt = '是否删除网络？';
                    break;
                case 5:
                    url = '/flavor/remove';operationTxt = '规格删除成功';$scope.txt = '是否删除规格？';
                    break;
                case 6:
                    url = '/subnet/remove';operationTxt = '子网删除成功';$scope.txt = '是否删除子网？';
                    break;
                case 7:
                    url = '/port/remove';operationTxt = '端口删除成功';$scope.txt = '是否删除端口？';
                    break;
                case 8:
                    url = '/route/remove';operationTxt = '路由删除成功';$scope.txt = '是否删除路由？';
                    break;
            }
            $scope.ok = function(){
                httpLoad.loadData({
                    url:url,
                    method:'POST',
                    data: removeData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //路由ctrl
    app.controller('openstackrouteCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','$stateParams','openstackData',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,$stateParams,openstackData) {
            //$rootScope.moduleTitle = '资源中心 > 配置管理';
            $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            //获取配置管理列表
            $scope.getData = function(page){
                $scope.showDetail = false;
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId},"sign":"EQ"}];
                if($scope.searchByName&&$scope.searchByName!=""){
                    searchParam.push({"param":{"name":$scope.searchByName},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/route/list',
                    method: 'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success&&data.data.rows){
                            $scope.routeList = data.data.rows;
                            $scope.totalCount = data.data.total;
                            if(data.data.rows.length==0) {
                                $scope.isImageData = true;
                            } else $scope.isImageData = false;
                            $scope.routeList.forEach(function(item){
                                if(item.status=='ACTIVE') {
                                    item.status1 = '运行中';item.statusColor = 'success';
                                }else {
                                    item.status1 = item.status;item.statusColor = 'danger';
                                }
                                if(item.adminStateup + ''=='true') item.adminStateup1 = '开启';
                                else item.adminStateup1 = '关闭';
                            });
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            openstackData.routeFun = $scope.getData;
            //新增
            $scope.add = function($event){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/route/addRoute.html',
                    controller : 'addRouteModalCtrl'
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //编辑
            $scope.update = function($event,$index,row,key,size){
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/route/updateRoute.html',
                    controller : 'updateopenstackRouteModalCtrl',
                    resolve : {
                        idData : function(){
                            return row.id;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //删除
            $scope.remove = function(id,$event,$index,key){
                if($event) $event.stopPropagation();
                $scope.removeData= {"id" : id};
                var action = 8;
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/config/openstack/removeVolume.html',
                    controller : 'removeopenstackVolumeModalCtrl',
                    resolve : {
                        action : function(){
                            return action;
                        },
                        removeData : function(){
                            return $scope.removeData;
                        }
                    }
                });
                modalInstance.result.then(function(){
                    $scope.getData();
                },function(){});
            };
            //跳转详情页
            $scope.detail = function (id) {
                httpLoad.loadData({
                    url:'/route/detail',
                    method:'GET',
                    data: {id: id},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.routeDetail = data.data;
                            $scope.showDetail = $scope.isActive = true;

                            if($scope.routeDetail.status=='ACTIVE') {
                                $scope.routeDetail.status1 = '运行中';
                                $scope.routeDetail.statusColor = 'success';
                            }else{
                                $scope.routeDetail.status1 = $scope.routeDetail.status;
                                $scope.routeDetail.statusColor = 'danger';
                            }
                            if($scope.routeDetail.adminStateup + ''=='true') $scope.routeDetail.adminStateup1 = '开启';
                            else $scope.routeDetail.adminStateup1 = '关闭';
                        }
                    }
                });
            };
            //返回
            $scope.goBack = function(){
                $scope.isActive = false;
                $timeout(function() {
                    $scope.showDetail = false;
                }, 200);
            };
        }
    ]);
    //新增ctrl
    angular.module('app').controller('addRouteModalCtrl',['$rootScope','$scope','$modalInstance','httpLoad','openstackData',
        function($rootScope,$scope,$modalInstance,httpLoad,openstackData){ //依赖于modalInstance
            $scope.addData = {};
            $scope.statusData = [{"value":true,"name":"开启"},{"value":false,"name":"关闭"}];
            $scope.addData.adminStateup = true;
            //获取网络数据
            $scope.getNetworkData = function(){
                var params = {
                        simple : true
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId,"isRouterExternal":true},"sign":"EQ"}];
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/network/list',
                    method:'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            $scope.networkList = data.data.rows;
                        }
                    }
                });
            };
            $scope.getNetworkData();

            $scope.ok = function(){
                $scope.addData.id = openstackData.platformId;
                httpLoad.loadData({
                    url:'/route/create',
                    method:'POST',
                    data: $scope.addData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });

            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
    //编辑ctrl
    angular.module('app').controller('updateopenstackRouteModalCtrl',['$scope','$modalInstance','httpLoad','$stateParams','idData','openstackData',
        function($scope,$modalInstance,httpLoad,$stateParams,idData,openstackData){ //依赖于modalInstance
            $scope.updateData = {};
            $scope.statusData1 = [{"value":true,"name":"开启"},{"value":false,"name":"关闭"}];
            //获取详情数据反显
            $scope.getDetail = function(){
                httpLoad.loadData({
                    url:'/route/detail',
                    method:'GET',
                    data: {id: idData},
                    success:function(data){
                        if(data.success&&data.data){
                            $scope.vmDetail = data.data;
                            var updateItem = ['id','name','adminStateup','networkId'];
                            for(var i=0;i<updateItem.length;i++){
                                var item = updateItem[i];
                                $scope.updateData[item] = $scope.vmDetail[item];
                            }
                            $scope.updateData.adminStateup = ''+ $scope.updateData.adminStateup;
                        }
                    }
                });
            };
            $scope.getDetail();
            //获取网络数据
            $scope.getNetworkData = function(){
                var params = {
                        simple : true
                    },
                    searchParam = [{"param":{"vendorId":openstackData.platformId,"isRouterExternal":true},"sign":"EQ"}];
                params.params = JSON.stringify(searchParam);
                httpLoad.loadData({
                    url:'/network/list',
                    method:'POST',
                    data: params,
                    noParam: true,
                    success:function(data){
                        if(data.success){
                            $scope.networkList = data.data.rows;
                        }
                    }
                });
            };
            $scope.getNetworkData();

            $scope.ok = function(){
                $scope.updateData.id = idData;
                if($scope.updateData.networkId=='') delete $scope.updateData.networkId;
                httpLoad.loadData({
                    url:'/route/modify',
                    method:'POST',
                    data: $scope.updateData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close();
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            }
        }]);
})();